#include <cstring>
#include <cstdio>
#include <queue>

using namespace std;

#define min(a,b) (((a)<(b))?(a):(b))

int f[ 301 ][ 301 ], d[ 301 ];
queue<int> q;

int main( )
{
    int i, j, k, n, ans, x, y, ansb, p;
    while ( scanf("%d", &n) != EOF )
    {
        for ( i = 0; i < n; i++ )
            for ( j = 0; j < n; j++ )
                scanf("%d", &f[ i ][ j ]);
        memset( d, 0x3f, sizeof( d ) );
        for ( i = 1; i < n; i++ )
        {
            d[ i ] = f[ 0 ][ i ];
            q.push( i );
        }
        while ( !q.empty( ) )
        {
            p = q.front( );
            q.pop( );
            for ( i = 0; i < n; i++ )
                if ( d[ i ] > d[ p ] + f[ p ][ i ] )
                {
                    q.push( i );
                    d[ i ] = d[ p ] + f[ p ][ i ];
                }
        }
        ans = d[ n - 1 ];
        ansb = d[ 0 ];
        memset( d, 0x3f, sizeof( d ) );
        for ( i = 0; i < n - 1; i++ )
        {
            d[ i ] = f[ n - 1 ][ i ];
            q.push( i );
        }
        while ( !q.empty( ) )
        {
            p = q.front( );
            q.pop( );
            for ( i = 0; i < n; i++ )
                if ( d[ i ] > d[ p ] + f[ p ][ i ] )
                {
                    q.push( i );
                    d[ i ] = d[ p ] + f[ p ][ i ];
                }
        }
        ansb += d[ n - 1 ];
        printf("%d\n", min( ans, ansb ));
    }
    return 0;
}
